package day5.homework2;

import java.util.Random;

public class Guess {
    private Commodity[] commodities = new Commodity[3];
    public Integer inputPrice; // 用户输入的猜测价格
    public Commodity drawCommodity; // 抽中的商品


    public Commodity draw() {
        // 首先随机一个商品出来
        Random random = new Random();
        int index = random.nextInt(3); // 直接返回0~2的整数
        // 获取这个商品
        drawCommodity = commodities[index];
        return drawCommodity;
    }
    public Result playGuess() {
        if (inputPrice > drawCommodity.price) return Result.HIGH;
        if (inputPrice < drawCommodity.price) return Result.LOW;
        return Result.OK;
    }

    /**
     * 商品初始化方法
     */
    public void init() {
        commodities[0] = new Commodity();
        commodities[0].commodityName = "华为Meta40Pro手机";
        commodities[0].price = 9000;
        commodities[1] = new Commodity();
        commodities[1].commodityName = "小米苏7";
        commodities[1].price = 200000;
        commodities[2] = new Commodity();
        commodities[2].commodityName = "iphone15";
        commodities[2].price = 10000;
    }
}
